import java.util.ArrayList;
import java.util.List;

public class test15_10_29 {
    /*给你一个单链表的头节点 head ，请你判断该链表是否为
回文链表
。如果是，返回 true ；否则，返回 false 。



示例 1：

输入：head = [1,2,2,1]
输出：true
*/
    public static void main(String[] args) {

    }

    public class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }

    public static boolean isPalindrome(ListNode head) {
        List<Integer> vals = new ArrayList<>();
        ListNode current = head;
        while (current != null) {
            vals.add(current.val);
            current = current.next;
        }
        int front = 0;
        int back = vals.size() - 1;
        while (front < back) {
            if (!(vals.get(front).equals(vals.get(back))))
                return false;
            front++;
            back--;
        }
        return true;
    }
}
